<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:t="http://myfaces.apache.org/tomahawk"
                template="/pages/crud_modalTemplate.xhtml">
                
	<ui:param name="crudBean" value="#{arquitetoBean}" />
	
	<ui:define name="content">
		<a4j:form id="formularioPesquisa">
			<!-- Painel de Pesquisa -->
			<h:panelGroup id="panelGroupDePesquisa">
				<f:subview id="viewBusca">
					<table>
						<tr>
							<td class="tdCor" width="120px;"><h:outputText value="Nome"/></td>
							<td class="tdBranco">
								<h:inputText value="#{crudBean.searchObject.nome}" styleClass="baseField" size="70" maxlength="100" onblur="upperCase(this)"/>
							</td>
						</tr>
						<tr>
							<td class="tdCor"><h:outputText value="CPF"/></td>
							<td class="tdBranco">
								<h:inputText value="#{crudBean.searchObject.cpf}" styleClass="baseField" size="20" maxlength="14" onkeypress="return formataCPF(event, this);" onblur="completaCPF(this);"/>
							</td>
						</tr>
					</table>
				</f:subview>
				<div id="botao" style="visibility: visible;">
	                <table class="buttonTable">
	                    <tr>
	                        <td class="buttonItem">
								<a4j:commandButton value="Pesquisar" actionListener="#{crudBean.pesquisar}" reRender="tblData"/>
								<h:outputText value=" "/>
								<a4j:commandButton value="Novo" actionListener="#{crudBean.preparaInserir}" reRender="painelMundial" ajaxSingle="true" oncomplete="#{rich:component('modalGroupDeEdicao')}.show()"/>
	                        </td>
	                    </tr>
	                </table>
	            </div>
			</h:panelGroup>
		</a4j:form>
		
		<!-- Painel de Edição -->
		<h:panelGroup id="panelGroupDeEdicao">
			<f:subview id="viewEdicao">
				<rich:modalPanel id="modalGroupDeEdicao" width="600" height="400">
					<a4j:form id="formularioUpdate">
						<h:panelGroup id="panelTitle2">
			                <table class="messageTable">
			                    <tr>
			                        <td class="tituloform">
			                            <b>
			                            	<h:outputText value="Arquiteto - Inserir" rendered="#{crudBean.inserting}"/>
			                            	<h:outputText value="Arquiteto - Alterar" rendered="#{crudBean.editing}"/>
			                            </b>
			                        </td>
			                    </tr>
			                    <tr>
			                        <td><ui:insert name="requiredFieldsMessage" /></td>
			                    </tr>
			                    <tr>
			                      <td>
			                        <a4j:outputPanel ajaxRendered="true" >
			                            <rich:messages layout="table" warnClass="msgWarm" errorClass="msgError" infoClass="msgInfo" globalOnly="true" />
			                        </a4j:outputPanel>
			                      </td>             
			                    </tr>
			                    <tr>
			                    	<td>
			                    		<h:outputText value="#{bundle.todosCamposObrigatorios}"/>
			                    	</td>
			                    </tr>
			                </table>
			            </h:panelGroup>
			            
			            <br />
			            
						<table>
							<tr>
								<td class="tdCor" width="120px;"><h:outputText value="Nome *"/></td>
								<td class="tdBranco">
									<h:inputText id="descricao" value="#{crudBean.entity.nome}" styleClass="baseField" size="30" maxlength="100" required="true" requiredMessage=" #{bundle.campoobrigatoriopagina}" onblur="upperCase(this)"/>
									<rich:message for="descricao" style="color: red;">
										<f:facet name="errorMarker">
											<h:graphicImage value="/imagens/alerta.png"/>   
										</f:facet>
									</rich:message>
								</td>
							</tr>
							<tr>
								<td class="tdCor"><h:outputText value="CPF"/></td>
								<td class="tdBranco">
									<h:inputText value="#{crudBean.entity.cpf}" styleClass="baseField" size="20" maxlength="14" onkeypress="return formataCPF(event, this);" onblur="completaCPF(this);"/>
								</td>
							</tr>
							<tr>
								<td class="tdCor" width="120px;"><h:outputText value="CEP"/></td>
								<td class="tdBranco">
									<h:inputText value="#{crudBean.entity.cep}" styleClass="baseField" size="15" maxlength="10" onkeypress="return formataCEP(event,this)"/>
								</td>
							</tr>
							<tr>
								<td class="tdCor" width="120px;"><h:outputText value="Logradouro"/></td>
								<td class="tdBranco">
									<h:inputText value="#{crudBean.entity.logradouro}" styleClass="baseField" size="70" maxlength="100" onblur="upperCase(this)"/>
								</td>
							</tr>
							<tr>
								<td class="tdCor" width="120px;"><h:outputText value="Número"/></td>
								<td class="tdBranco">
									<h:inputText value="#{crudBean.entity.numero}" styleClass="baseField" size="8" maxlength="5" onkeypress="return soNumero(event,this)"/>
								</td>
							</tr>
							<tr>
								<td class="tdCor" width="120px;"><h:outputText value="Complemento"/></td>
								<td class="tdBranco">
									<h:inputText value="#{crudBean.entity.complemento}" styleClass="baseField" size="70" maxlength="100" onblur="upperCase(this)"/>
								</td>
							</tr>
							<tr>
								<td class="tdCor" width="120px;"><h:outputText value="Bairro"/></td>
								<td class="tdBranco">
									<h:inputText value="#{crudBean.entity.bairro}" styleClass="baseField" size="70" maxlength="100" onblur="upperCase(this)"/>
								</td>
							</tr>
							<tr>
								<td class="tdCor" width="120px;"><h:outputText value="Cidade"/></td>
								<td class="tdBranco">
									<h:inputText value="#{crudBean.entity.cidade}" styleClass="baseField" size="70" maxlength="100" onblur="upperCase(this)"/>
								</td>
							</tr>
							<tr>
								<td class="tdCor" width="120px;"><h:outputText value="UF"/></td>
								<td class="tdBranco">
									<h:inputText value="#{crudBean.entity.uf}" styleClass="baseField" size="5" maxlength="2" onblur="upperCase(this)"/>
								</td>
							</tr>
							<tr>
								<td class="tdCor" width="120px;"><h:outputText value="Email"/></td>
								<td class="tdBranco">
									<h:inputText value="#{crudBean.entity.email}" styleClass="baseField" size="70" maxlength="100" onblur="upperCase(this)"/>
								</td>
							</tr>
							<tr>
								<td class="tdCor" width="120px;"><h:outputText value="Telefone"/></td>
								<td class="tdBranco">
									<h:inputText value="#{crudBean.entity.ddd}" styleClass="baseField" size="4" maxlength="2" onkeypress="return soNumero(event,this)"/>
									-
									<h:inputText value="#{crudBean.entity.numeroTelefone}" styleClass="baseField" size="10" maxlength="9" onkeypress="return formataTelefone(event,this)"/>
								</td>
							</tr>
						</table>
						<div id="botao" style="visibility: visible;">
			                <table class="buttonTable">
			                    <tr>
			                        <td class="buttonItem">
										<a4j:commandButton value="Gravar" actionListener="#{crudBean.inserir}" reRender="formularioUpdate, formularioPesquisa, tblData" oncomplete="if (#{crudBean.searching}) #{rich:component('modalGroupDeEdicao')}.hide();" rendered="#{crudBean.inserting}"/>
										<a4j:commandButton value="Alterar" actionListener="#{crudBean.alterar}" reRender="formularioUpdate, formularioPesquisa, tblData" oncomplete="if (#{crudBean.searching}) #{rich:component('modalGroupDeEdicao')}.hide();" rendered="#{crudBean.editing}"/>
										<h:outputText value=" "/>
										<a4j:commandButton value="Fechar" actionListener="#{crudBean.cancelar}" oncomplete="#{rich:component('modalGroupDeEdicao')}.hide()" reRender="formularioUpdate, formularioPesquisa, tblData" ajaxSingle="true"/>
			                        </td>
			                    </tr>
			                </table>
			            </div>
		            </a4j:form>
				</rich:modalPanel>
			</f:subview>
		</h:panelGroup>
	</ui:define>
	
	<ui:define name="list">
		<a4j:form id="formularioLista">
			<f:subview id="viewListagem" rendered="#{crudBean.searching}">
				<rich:dataTable id="tblData" value="#{crudBean.searchResult}" binding="#{crudBean.tblData}" var="rst" style="width: 100%;" rowClasses="par,impar">
					<f:facet name="header">
						<rich:columnGroup>
							<rich:column style="text-align: left;">
								<h:outputText value="Nome"/>
							</rich:column>
							<rich:column style="text-align: left;">
								<h:outputText value="CPF"/>
							</rich:column>
							<rich:column style="text-align: left;">
								<h:outputText value="Email"/>
							</rich:column>
							<rich:column style="text-align: left;">
								<h:outputText value="Telefone"/>
							</rich:column>
							<rich:column style="text-align: center;">
								<h:outputText value="CEP"/>
							</rich:column>
							<rich:column style="text-align: left;">
								<h:outputText value="Logradouro"/>
							</rich:column>
							<rich:column style="text-align: right;">
								<h:outputText value="Numero"/>
							</rich:column>
							<rich:column style="text-align: left;">
								<h:outputText value="Complemento"/>
							</rich:column>
							<rich:column style="text-align: left;">
								<h:outputText value="Bairro"/>
							</rich:column>
							<rich:column style="text-align: left;">
								<h:outputText value="Cidade"/>
							</rich:column>
							<rich:column style="text-align: left;">
								<h:outputText value="UF"/>
							</rich:column>
							<rich:column style="text-align: center;">
							</rich:column>
							<rich:column style="text-align: center;">
							</rich:column>
						</rich:columnGroup>
					</f:facet>
					
					<rich:column style="text-align: left;">
						<h:outputText value="#{rst.nome}"/>
					</rich:column>
					<rich:column style="text-align: left;">
						<h:outputText value="#{rst.cpf}"/>
					</rich:column>
					<rich:column style="text-align: left;">
						<h:outputText value="#{rst.email}"/>
					</rich:column>
					<rich:column style="text-align: left;">
						<h:outputText value="(#{rst.ddd}) #{rst.numeroTelefone}" rendered="#{rst.ddd != null and rst.numeroTelefone != null}"/>
					</rich:column>
					<rich:column style="text-align: center;">
						<h:outputText value="#{rst.cep}"/>
					</rich:column>
					<rich:column style="text-align: left;">
						<h:outputText value="#{rst.logradouro}"/>
					</rich:column>
					<rich:column style="text-align: right;">
						<h:outputText value="#{rst.numero}"/>
					</rich:column>
					<rich:column style="text-align: left;">
						<h:outputText value="#{rst.complemento}"/>
					</rich:column>
					<rich:column style="text-align: left;">
						<h:outputText value="#{rst.bairro}"/>
					</rich:column>
					<rich:column style="text-align: left;">
						<h:outputText value="#{rst.cidade}"/>
					</rich:column>
					<rich:column style="text-align: left;">
						<h:outputText value="#{rst.uf}"/>
					</rich:column>
					<rich:column style="text-align: center;">
						<a4j:commandButton image="/imagens/alterar.png" style="border:white;" title="ALTERAR" actionListener="#{crudBean.preparaAlterar}" reRender="painelMundial" ajaxSingle="true" oncomplete="#{rich:component('modalGroupDeEdicao')}.show()"/>
					</rich:column>
					<rich:column style="text-align: center;">
						<a4j:commandButton image="/imagens/inativar.png" style="border:white;" title="EXCLUIR" actionListener="#{crudBean.inativar}" reRender="painelMundial, formularioLista" onclick="if (!confirm('Deseja realmente inativar este arquiteto?')) return false"/>
					</rich:column>
				</rich:dataTable>
			</f:subview>
		</a4j:form>
	</ui:define>
        

</ui:composition>